package com.nbsaas.boot.app.data.entity;

import com.nbsaas.boot.code.annotation.FieldConvert;
import com.nbsaas.boot.code.annotation.FieldName;
import com.nbsaas.boot.code.annotation.FormAnnotation;
import com.nbsaas.boot.code.annotation.SearchItem;
import com.nbsaas.boot.jpa.data.entity.LongEntity;
import com.nbsaas.boot.rest.filter.Operator;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;

@Data
@FormAnnotation(model = "应用用户角色")
@Entity
@Comment("应用用户角色")
@Table(name = "sys_app_user_role")
public class AppUserRole extends LongEntity {

    @SearchItem(label = "用户", name = "userId", classType = Long.class, operator = Operator.eq)
    @Comment("用户id")
    private Long userId;

    @SearchItem(label = "角色", name = "role", key = "role.id", classType = Long.class, operator = Operator.eq)
    @JoinColumn(name = "role_id")
    @FieldConvert
    @FieldName
    @Comment("角色id")
    @ManyToOne(fetch = FetchType.LAZY)
    private AppRole role;

    @JoinColumn(name = "app_id", foreignKey = @ForeignKey(ConstraintMode.PROVIDER_DEFAULT))
    @Comment("应用")
    @SearchItem(label = "应用", name = "app", key = "app.id", classType = Long.class, operator = Operator.eq)
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private App app;


    @SearchItem(label = "租户id", name = "tenantId", classType = Long.class, operator = Operator.eq)
    @Comment("租户id")
    private Long tenantId;
}
